<!--  -->
<template>
  <div class="app-container">
    <div class="search-and-button1">
      <ImportFile url="/sale/statistics/order/import" @getTableInfo="getTableInfo" />
      <el-button type="primary" icon="el-icon-search" @click="getTableInfo()">查询</el-button>
    </div>
    <el-row class="table">
      <el-table v-loading="loading" :data="tableData" ref="tableData" stripe border>
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column align="center" type="index" label="索引" width="60px" />
        <el-table-column v-for="item in fields" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val" :min-width="item.width + 'px'">
          <template #default="{ row }">
            <span v-if="item.code.split(':')[1] === 'saleForecast'">
              <b style="font-weight:normal;" :class="row.saleForecast !== '-' ? 'colorRed':''">{{ row.saleForecast }}</b>
            </span>
            <span v-else-if="item.code.split(':')[1] === 'forecastRate'">
              <b style="font-weight:normal;" :class="row.forecastRate !== '-' ? 'colorRed':''">{{ row.forecastRate }}</b>
            </span>
            <span v-else-if="item.code.split(':')[1] === 'growthStr'">
              <b :class="row.growthStr.substr(0, 1)  === '-' ? 'green':'colorRed'">{{ row.growthStr }}</b>
            </span>

            <span v-else>{{ row[item.code.split(':')[1]] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-row>

    <el-row>
      <div class="table-btn-box">
        <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row, true)
              })
            }
          ">选择全部</el-button>
        <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row)
              })
            }
          ">反向选择</el-button>
        <el-button>
          更多菜单
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
      </div>
    </el-row>
  </div>
</template>
<script>
import ImportFile from '@/components/ImportFile'
export default {
  components: { ImportFile },
  props: {
    fields: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      loading: false,
      tableData: [],
      show: false,
      customColors: [
        { color: '#f56c6c', percentage: 30 },
        { color: '#e6a23c', percentage: 60 },
        { color: '#1989fa', percentage: 80 },
        { color: '#2ed573', percentage: 100 }
      ]
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.getTableInfo()
  },
  beforeDestroy() {
    window.onresize = null
  },
  methods: {
    getInfo() {
      this.getTableInfo()
    },
    /**
     * @description: page
     * @param {*} page
     * @return {*}
     */
    async getTableInfo() {
      this.loading = true
      const res = await this.$axios.post('/sale/operation/operationList')
      if (res?.data.code === 200) {
        this.tableData = res.data.data
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.colorRed {
  color: red;
}
.green {
  color: green;
}
.app-container {
  padding: 0px;
}
.search-and-button1 {
  min-height: 33px;
  line-height: 30px;
  height: 30px !important;
  overflow: hidden;
  transition: height 0.3s;
  width: 100%;
  .el-input {
    width: 350px;
    float: right;
  }
}
.table {
  margin-top: 10px;
  .rateStyle {
    padding-top: 5px !important;
  }
}
</style>
